from django.db import models
from dingxiang.utils.models import BaseModel
# Create your models here.


# 药品系统
class MedicineSystem(BaseModel):
    name = models.CharField(max_length=20, null=True, blank=True, verbose_name='药品系统名称')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'medicine_system'
        verbose_name_plural = '药品系统'

# 药品类型
class MedicineType(BaseModel):
    name = models.CharField(max_length=20, null=True, blank=True, verbose_name='药品类型名称')
    system = models.ForeignKey(MedicineSystem, null=True, blank=True, on_delete=models.DO_NOTHING, related_name="system_type", verbose_name='药品系统')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'medicine_type'
        verbose_name_plural = '药品类型'

# 药品公司
class MedicineCompany(BaseModel):
    name = models.CharField(max_length=20, null=True, blank=True, verbose_name='药品公司名称')
    type = models.ForeignKey(MedicineType, null=True, blank=True, on_delete=models.DO_NOTHING, related_name="type_company", verbose_name='药品类型')

    def __str__(self):
        return self.name

    class Meta():
        db_table = 'medicine_company'
        verbose_name_plural = '药品公司'

# 药品详情
class FindMedicine(BaseModel):
    # 标题
    title = models.CharField(max_length=255, verbose_name="标题")
    # 核准日期
    approval_date = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='核准日期')
    # 修改日期
    modification_date = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='修改日期')
    # 成份
    Ingredients = models.TextField(verbose_name='成份', null=True, blank=True)
    # 规格
    Specifications = models.TextField(verbose_name='规格', null=True, blank=True)
    # 适应症
    indication = models.TextField(verbose_name='适应症', null=True, blank=True)
    # 用法用量
    Usage_dosage = models.TextField(verbose_name='用法用量', null=True, blank=True)
    # 禁忌
    taboo = models.TextField(verbose_name='禁忌', null=True, blank=True)
    # 注意事请
    matters_needing_attention = models.TextField(verbose_name='注意事请', null=True, blank=True)
    # 药理作用
    pharmacological_action = models.TextField(verbose_name='药理作用', null=True, blank=True)
    # 药代动力学
    Pharmacokinetics = models.TextField(verbose_name='药代动力学', null=True, blank=True)
    # 化学成份
    chemical_composition = models.TextField(verbose_name='化学成份', null=True, blank=True)
    # 上市许可持有人
    listing_authorization_holder = models.TextField(verbose_name='上市许可持有人', null=True, blank=True)
    # 生产企业
    manufacturing_enterprise = models.TextField(verbose_name='生产企业', null=True, blank=True)
    company = models.ManyToManyField(MedicineCompany, null=True, blank=True, related_name="type_company", verbose_name='药品类型')

    class Meta:
        db_table = 'find_medicine'
        verbose_name_plural = '查找药物'

    def __str__(self):
        return self.title